<template>
	<div>
		<div v-if="!isBatchImport">
			<div class="topTitle">{{topTitle||''}}</div>
			<el-form inline :model="query" label-width="80px">
				<el-form-item label="科目" v-if="page=='famousQuestion'">
					<el-select placeholder="请选择科目" v-model="query.appid" class="margin-right10 width260" @change="appChange">
						<el-option v-for="miniApp in miniApps" :key="miniApp.id" :label="miniApp.name"
							:value="miniApp.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="题型">
					<el-select v-model="query.type" placeholder="请选择题型" clearable class="margin-right10 width260">
						<el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<template v-if="page!='train'">
					<el-form-item label="章节分类">
						<el-select filterable v-model="query.categoryId3" placeholder="请选择章节分类" clearable
							class="width260 margin-right10">
							<el-option v-for="item in categoryId3Data" :key="item.id" :label="item.name" :value="item.id"
								:style="{'color': item.color?item.color:''}"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="模块分类">
						<el-select filterable v-model="query.categoryId2" placeholder="请选择模块分类" :clearable="true"
							class="margin-right10 width260">
							<el-option v-for="point in categoryId2Data" :key="point.id" :label="point.name"
								:value="point.id"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="综合分类" v-if="page!='smallQuestionList'">
						<el-select filterable v-model="query.categoryId1" placeholder="请选择综合分类" clearable
							class="width260 margin-right10">
							<el-option v-for="item in categoryId1Data" :key="item.id" :label="item.name" :value="item.id"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="题目属性">
						<el-select v-model="query.properType" placeholder="请选择题目属性" clearable class="margin-right10 width260">
							<el-option label="普通题" :value="1"></el-option>
							<el-option label="作废题" :value="2"></el-option>
							<el-option label="争议题" :value="3"></el-option>
							<el-option label="重复题" :value="4"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="来源地区" v-if="page!='smallQuestionList'&&page!='famousQuestion'">
						<el-cascader :props="props" v-model="query.city" :options="areaData" placeholder="请选择地区"
							class="margin-right10 width260">
						</el-cascader>
					</el-form-item>
					<el-form-item label="来源年份">
						<el-date-picker style="width: 260px;" class="margin-right10" v-model="query.questionSourceYear" type="year"
							placeholder="来源年份" value-format="yyyy">
						</el-date-picker>
					</el-form-item>
					<el-form-item label="题目标签">
						<el-select v-model="query.labelIds" multiple filterable placeholder="请选择题目标签" clearable
							class="margin-right10 width260">
							<el-option :label="item.name" v-for="item in tagList" :key="item.id" :value="item.id"></el-option>
						</el-select>
					</el-form-item>
				</template>
				<el-form-item label="模糊搜索">
					<el-input placeholder="请输入关键字" v-model="query.title" class="width260 margin-right10"></el-input>
				</el-form-item>
				<el-checkbox v-model="query.searchOption">只搜选项
				</el-checkbox>
				<el-checkbox v-model="query.answerOption">只搜答案
				</el-checkbox>
				<el-button type="primary" icon="el-icon-search" class="margin-left10" @click="handleSearch">搜索</el-button>
				<el-button type="default" icon="el-icon-refresh-right" @click="handleRefresh">重置</el-button>
			</el-form>
			<div class="row-me margin-top20">
				<template v-if="page=='famousQuestion'">
					<el-button type="primary" @click="handleBatchAdd">批量添加</el-button>
					<el-button type="primary" @click="[query.ran=1,handleSearch()]">随机</el-button>
				</template>
				<template v-else>
					<el-button type="primary" class="margin-right20" @click="delAllSelection" v-if="roleType==3">批量删除</el-button>
					<el-button type="primary" class="margin-right20" v-if="page!='train'&&roleType==3"
						@click="editCategoryVisible = true">批量修改分类</el-button>
					<el-button type="primary" class="margin-right20" v-if="page!='train'&&roleType==3"
						@click="[editTagVisible=true,editTagForm={}]">批量修改标签</el-button>
					<el-button type="primary" class="margin-right20" @click="batchExport">批量导出</el-button>
					<el-button type="primary" class="margin-right20" v-if="page!='train'&&roleType==3"
						@click="isBatchImport=true">批量导入</el-button>
					<el-button type="warning" @click="clickRenew" v-if="roleType==3">一键更新</el-button>
				</template>
			</div>
			<el-table :data="tableData" ref="multipleTable" border class="margin-top20"
				header-cell-class-name="table-header-style" @selection-change="handleSelectionChange" row-key="id"
				:expand-row-keys="expands">
				<el-table-column type="expand" width="0">
					<template slot-scope="scope">
						<div style="max-width:50vw;max-height: 500px;overflow-y: scroll;" class="margin-left20"
							v-if="scope.row.type.value==99||scope.row.type.value==114||scope.row.type.value==113||scope.row.type.value==115">
							<div class="color252525 margin-right10">题目：<span v-html="scope.row.title"></span></div>
							<div v-for="(item,index) in scope.row.clozeList" :key="index" class="margin-top30">
								<div class="color252525">
									<div class="row-me">{{index+1}}.<div v-html="item.title"></div>
									</div>
									<div v-if="item.content">
										<div class="margin-top10" v-for="(val,i) in JSON.parse(item.content)" :key="i">
											{{val.title}}.<img class="width100" v-if="judgeImg(val.content)" :src="val.content" alt=""> <span
												v-else>{{val.content}}</span>
										</div>
									</div>
								</div>
								<div class="row-me margin-top10">
									<span class="color929397 margin-right10">答案</span>
									<div class="color252525 flex1 line-height21 row-me"><span
											class="colorEE010B font-weight600 margin-right5" v-html="item.answer"></span>
										<div class="row-me">
											<div v-html="item.textExplain"></div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div style="max-width:50vw;" class="margin-left20" v-else>
							<div class="row-me">
								<span class="color929397 margin-right10">题目</span>
								<div class="flex1 color252525">
									<div style="white-space:pre-line" v-html="scope.row.title"></div>
									<div v-if="scope.row.type.value!=100">
										<div class="margin-top10" v-for="(item,index) in scope.row.optionList" :key="index">
											{{item.title}}.<img class="width100" v-if="judgeImg(item.content)" :src="item.content" alt="">
											<span v-else v-html="item.content"></span>
										</div>
									</div>
								</div>
							</div>
							<div class="row-me margin-top10" style="max-height: 500px;overflow-y: auto;"
								v-if="scope.row.type.value==100">
								<span class="color929397 margin-right10">答案</span>
								<div class="flex1">
									<div v-for="(item,index) in scope.row.clozeList" :key="index"
										class="color252525 flex1 line-height21 margin-bottom10">
										<div v-if="item.content">
											<div v-for="(val,i) in JSON.parse(item.content)" :key="i">{{val.title||''}}、{{val.content||''}}
											</div>
										</div>
										<div class="row-me">
											<span class="colorEE010B font-weight600 margin-right5">{{item.answer}}</span>
											<div class="row-me">
												<div v-html="item.textExplain"></div>
											</div>
										</div>
									</div>
								</div>
							</div>
							<div class="row-me margin-top10" v-else>
								<span class="color929397 margin-right10">答案</span>
								<div class="color252525 flex1 line-height21 row-me"><span
										class="colorEE010B font-weight600 margin-right5" v-html="scope.row.answer"></span>
									<div class="row-me">
										<div v-html="scope.row.textExplain"></div>
									</div>
								</div>
							</div>
						</div>
						<div class="row-me row-center margin-top10 margin-left20">
							<span class="color929397 margin-right10">来源</span>
							<div class="row-me flex-wrap">
								<el-tag class="margin-right10" v-for="(item,index) in scope.row.examSource"
									:key="index">{{item}}</el-tag>
								<el-tag class="margin-right10" v-for="(item,index) in scope.row.questionSources" :key="index" closable
									@close="questionSourceClose(item.id)">{{item.name}}</el-tag>
								<el-button type="primary" class="el-icon-edit margin-left10"
									@click="clickAddSource(scope.row)">增加来源</el-button>
							</div>
						</div>
					</template>
				</el-table-column>
				<el-table-column type="selection" width="55" align="center"></el-table-column>
				<el-table-column type="index" width="55" align="center" label="序号"></el-table-column>
				<el-table-column prop="id" label="题目ID" align="center" width="100"></el-table-column>
				<el-table-column label="题目" :show-overflow-tooltip="true" width="600">
					<template slot-scope="{row}">
						<span v-if="row.title" class="line2" v-html="row.title"></span>
						<span v-else>{{row.name||''}}</span>
					</template>
				</el-table-column>
				<el-table-column prop="type.name" width="100" label="题型" align="center"></el-table-column>
				<el-table-column prop="organName" label="发布机构" align="center" v-if="page=='train'"></el-table-column>
				<el-table-column prop="className" label="分类" align="center" v-if="page=='smallQuestionList'"></el-table-column>
				<el-table-column width="300" label="分类" align="center" v-if="page!='train'&&page!='smallQuestionList'">
					<template slot-scope="{row}">
						<span class="line1">{{ row.category3 }}/{{ row.category2 }}/{{row.category1 }}</span>
					</template>
				</el-table-column>
				<el-table-column width="100" label="属性" align="center" v-if="page!='train'">
					<template slot-scope="{row}">
						<span v-if="row.properType==1">普通题</span>
						<span v-else-if="row.properType==2">作废题</span>
						<span v-else-if="row.properType==3">争议题</span>
						<span v-else-if="row.properType==4">重复题</span>
					</template>
				</el-table-column>
				<el-table-column prop="labelName" label="标签分类" align="center" v-if="page!='train'">
					<template slot-scope="scope">
						<el-tag class="margin-right10" v-for="(item,index) in scope.row.labelName"
							:key="index">{{item.name||''}}</el-tag>
					</template>
				</el-table-column>
				<template v-if="page!='famousQuestion'">
					<el-table-column label="相关考点" width="100" align="center" v-if="page!='train'">
						<template slot-scope="scope">
							<el-tag type="success" class="pointer" v-if="scope.row.pointsId"
								@click="getExam(scope.$index, scope.row)">查看</el-tag>
							<el-button type="text" v-else @click="getExam(scope.$index, scope.row)">关联</el-button>
						</template>
					</el-table-column>
					<el-table-column width="100" label="解析视频" align="center" v-if="page!='train'">
						<template slot-scope="scope">
							<el-tag type="success" class="pointer" v-if="scope.row.videoCount" @click="getVideoAnalysis(scope.row)">
								查看
							</el-tag>
							<el-button type="text" v-else @click="getVideoAnalysis(scope.row)">关联</el-button>
						</template>
					</el-table-column>
					<el-table-column width="110" label="评论" align="center" v-if="page!='train'">
						<template slot-scope="scope">
							<span class="blue-text" @click="searchComment(scope.row.id)">{{scope.row.commentCount||0}}</span>
						</template>
					</el-table-column>
					<el-table-column width="100" label="纠错" align="center" v-if="page!='train'&&roleType==3">
						<template slot-scope="scope">
							<el-switch v-model="scope.row.showCorrecting" @change="(val)=>showCorrectingChange(val,scope.row)">
							</el-switch>
						</template>
					</el-table-column>
					<el-table-column width="100" label="主题目" align="center" v-if="page=='smallQuestionList'">
						<template slot-scope="scope">
							<el-tag type="danger" class="pointer" @click="clickTheme(scope.row)" v-if="scope.row.parentId">查看</el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="accurate" label="正确率" width="100" align="center"></el-table-column>
					<el-table-column label="操作" width="240px" align="center" fixed="right">
						<template slot-scope="scope">
							<div class="row-me center-all">
								<div v-if="page!='train'">
									<el-button type="text" @click="handleEdit(scope.row,1)" v-if="roleType==3 || roleType==1">编辑</el-button>
									<el-button type="text" @click="handleAppQrcode(scope.row)">二维码</el-button>
									<el-button type="text" @click="handleHistoryError(scope.row)" v-if="roleType==3">历史纠错</el-button>
								</div>
								<div v-else>
									<el-button type="text" @click="handleEdit(scope.row,2)">添加到题库系统</el-button>
								</div>
								<el-popconfirm title="确定删除吗？" @confirm="handleDel(scope.row.id)" v-if="roleType==3 || roleType==1">
									<el-button type="text" slot="reference" class="margin-left10">删除</el-button>
								</el-popconfirm>
							</div>
						</template>
					</el-table-column>
				</template>
			</el-table>
			<div class="margin-top10">
				<el-pagination background layout="->,total,sizes, prev, pager, next" :current-page="query.pageNumber"
					:page-sizes="[30, 40, 50, 60]" @size-change="handleSizeChange" :page-size="query.pageSize" :total="pageTotal"
					@current-change="handlePageChange"></el-pagination>
			</div>

			<!-- 批量修改分类 -->
			<el-dialog title="批量修改分类" :visible.sync="editCategoryVisible" width="600px">
				<div class="row-me center-all">
					<el-form :model="editCategoryForm" label-width="80px">
						<el-form-item label="章节分类">
							<el-select filterable v-model="editCategoryForm.categoryId3" placeholder="请选择章节分类" :clearable="true"
								class="width300">
								<el-option v-for="point in categoryId3Data" :key="point.id" :label="point.name" :value="point.id"
									:style="{'color': point.color?point.color:''}"></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="模块分类">
							<el-select filterable v-model="editCategoryForm.categoryId2" placeholder="请选择模块分类" :clearable="true"
								class="width300">
								<el-option v-for="point in categoryId2Data" :key="point.id" :label="point.name"
									:value="point.id"></el-option>
							</el-select>
						</el-form-item>
						<el-form-item label="综合分类">
							<el-select v-model="editCategoryForm.categoryId1" class="width300" placeholder="请选择综合分类"
								:clearable="true">
								<el-option v-for="point in categoryId1Data" :key="point.id" :label="point.name"
									:value="point.id"></el-option>
							</el-select>
						</el-form-item>
					</el-form>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="editCategoryVisible = false">取 消</el-button>
					<el-button type="primary" @click="handleCategorySave">确 定</el-button>
				</span>
			</el-dialog>

			<!-- 批量修改标签 -->
			<el-dialog title="批量修改标签" :visible.sync="editTagVisible" width="600px">
				<div class="row-me center-all">
					<el-form :model="editTagForm" label-width="80px">
						<el-form-item label="题目标签">
							<el-select v-model="editTagForm.labelIds" filterable placeholder="请选择题目标签" multiple clearable
								class="margin-right30 width260">
								<el-option :label="item.name" v-for="item in tagList" :key="item.id" :value="item.id"></el-option>
							</el-select>
						</el-form-item>
					</el-form>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="editTagVisible = false">取 消</el-button>
					<el-button type="primary" @click="handleTagSave">确 定</el-button>
				</span>
			</el-dialog>

			<!-- 查看主题目 -->
			<el-dialog title="查看主题目" :visible.sync="themeVisible" width="65%">
				<el-table :data="themeData" border class="table" header-cell-class-name="table-header-style">
					<el-table-column label="序号" type="index" width="80" align="center"></el-table-column>
					<el-table-column prop="id" label="题目ID" align="center"></el-table-column>
					<el-table-column label="题目" :show-overflow-tooltip="true" width="500">
						<template slot-scope="{row}">
							<span class="line1">{{row.title}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="type.name" width="100" label="题型" align="center"></el-table-column>
					<el-table-column width="300" label="分类" align="center">
						<template slot-scope="{row}">
							<span class="line1">{{ row.category3 }}/{{ row.category2 }}/{{row.category1 }}</span>
						</template>
					</el-table-column>
					<el-table-column width="100" label="属性" align="center">
						<template slot-scope="{row}">
							<span v-if="row.properType==1">普通题</span>
							<span v-else-if="row.properType==2">作废题</span>
							<span v-else-if="row.properType==3">争议题</span>
							<span v-else-if="row.properType==4">重复题</span>
						</template>
					</el-table-column>
					<el-table-column label="标签分类" align="center">
						<template slot-scope="scope">
							<div class="row-me flex-wrap" v-if="scope.row.labelName">
								<el-tag class="margin-right10" v-for="(item,index) in scope.row.labelName"
									:key="index">{{item.name}}</el-tag>
							</div>
						</template>
					</el-table-column>
					<el-table-column prop="accurate" label="正确率" width="100" align="center"></el-table-column>
				</el-table>
				<span slot="footer" class="dialog-footer">
					<el-button @click="themeVisible = false" type="primary">关 闭</el-button>
				</span>
			</el-dialog>

			<!-- 历史纠错 -->
			<el-dialog title="历史纠错" :visible.sync="historyErrorVisible" width="60%">
				<el-table :data="historyErrorData" border class="table" header-cell-class-name="table-header">
					<el-table-column type="index" label="序号" width="55" align="center"></el-table-column>
					<el-table-column prop="content" label="纠错内容" align="center"></el-table-column>
					<el-table-column prop="content" label="纠错类型" align="center"></el-table-column>
					<el-table-column prop="content" label="纠错人电话" align="center"></el-table-column>
					<el-table-column prop="content" label="纠错时间" align="center"></el-table-column>
				</el-table>
				<div class="margin-top10">
					<el-pagination background layout="->,total,sizes, prev, pager, next" :current-page="historyQuery.pageNumber"
						:page-sizes="[30, 40, 50, 60]" @size-change="handleHistorySizeChange" :page-size="historyQuery.pageSize"
						:total="historyPageTotal" @current-change="handleHistoryPageChange"></el-pagination>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="historyErrorVisible=false">取 消</el-button>
					<el-button type="primary" @click="historyErrorVisible=false">确 定</el-button>
				</span>
			</el-dialog>

			<!-- 编辑 -->
			<el-dialog :title="title" :visible.sync="editVisible" width="70%" :modal-append-to-body="false" append-to-body>
				<examQuestions ref="examQuestions" :isSmall="isSmall" :isChild="isSmall" @handleOk="handleOk"></examQuestions>
			</el-dialog>

			<!-- 二维码弹出框 -->
			<el-dialog title="试题二维码" :visible.sync="appQrcodeVisible" width="20%">
				<div id="qrCode">
					<div id='code' ref="appQrCodeUrl" title="" align="center"></div>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="appQrcodeVisible = false">取 消</el-button>
					<el-button @click="handleDownloadAppQrIMg">下载</el-button>
				</span>
			</el-dialog>

			<!-- 增加来源 -->
			<el-dialog title="增加来源" :visible.sync="sourceVisible" width="600px" append-to-body>
				<div class="row-me center-all">
					<el-form :model="sourceForm" label-width="80px">
						<el-form-item label="来源名称">
							<el-input v-model="sourceForm.name" class="width300" placeholder="请输入名称"></el-input>
						</el-form-item>
						<el-form-item label="来源年份">
							<el-date-picker v-model="sourceForm.year" type="year" placeholder="选择年份" style="width:300px;"
								value-format="yyyy">
							</el-date-picker>
						</el-form-item>
						<el-form-item label="来源地区">
							<el-cascader :props="{value: 'id',label: 'name',checkStrictly: true}" v-model="sourceForm.area"
								:options="areaData" placeholder="请选择地区" class="width300" @change="areaChange">
							</el-cascader>
						</el-form-item>
					</el-form>
				</div>
				<span slot="footer" class="dialog-footer">
					<el-button @click="sourceVisible=false">取 消</el-button>
					<el-button type="primary" @click="saveQuestionSource">确 定</el-button>
				</span>
			</el-dialog>

			<!--批量导出试题-->
			<batchExport ref="batchExport" :categoryId1Data="categoryId1Data" :categoryId2Data="categoryId2Data"
				:categoryId3Data="categoryId3Data" :typeList="typeList" :isChild="page == 'smallQuestionList'?true:false"
				:tagList="tagList" @exportOk="getData"></batchExport>

			<!-- 关联考点 -->
			<associatedExam ref="associatedExam" @handleExamOk="getData"></associatedExam>

			<!-- 关联视频 -->
			<associatedVideo ref="associatedVideo" @handleVideoOk="getData"></associatedVideo>

			<!-- 试题评论 -->
			<questionComment ref="questionComment" @handleCommentOk="getData"></questionComment>

			<!-- 一键更新 -->
			<renew ref="renew" @handleOk="getData"></renew>

		</div>
		<!-- 批量导入 -->
		<batchImport v-if="isBatchImport" :categoryId1Data="categoryId1Data" :categoryId2Data="categoryId2Data"
			:categoryId3Data="categoryId3Data" :typeList="typeList" :tagList="tagList" :page="page"
			@importOk='isBatchImport=false'>
		</batchImport>
	</div>
</template>

<script>
	import QRCode from 'qrcodejs2'
	import batchExport from '@/components/batchExport'
	import batchImport from '@/components/batchImport'
	import associatedExam from '@/components/associatedExam'
	import associatedVideo from '@/components/associatedVideo'
	import questionComment from '@/components/questionComment'
	import examQuestions from '@/components/examQuestions'
	import renew from '@/components/renew/index.vue'
	export default {
		props: ['page', 'topTitle', 'examPaperId',
			'examPaperTypeId', 'type', 'examPaperScore'
		], // page:smallQuestionList 小试题列表 page:train 机构题库 page:famousQuestion 名试题库
		components: {
			batchExport,
			batchImport,
			associatedExam,
			associatedVideo,
			questionComment,
			examQuestions,
			renew
		},
		data() {
			return {
				query: {
					pageNumber: 1,
					pageSize: 30
				},
				themeQuery: {
					pageNumber: 1,
					pageSize: 10
				},
				themePageTotal: 0,
				typeList: [],
				categoryId3Data: [],
				categoryId2Data: [],
				categoryId1Data: [],
				tableData: [],
				pageTotal: 0,
				multipleSelection: [],
				examId: '', //考点id
				examVisible: false,
				examData: [],
				tableExamtData: [],
				videoQuery: {},
				tagList: [],
				editCategoryVisible: false,
				editCategoryForm: {},
				editTagVisible: false,
				editTagForm: {},
				isBatchImport: false,
				themeVisible: false,
				themeData: [],
				title: '',
				editVisible: false,
				miniApps: [],
				props: {
					emitPath: false,
					value: 'id',
					label: 'name',
					checkStrictly: true,
				},
				citys: [],
				areaData: [],
				appQrcodeVisible: false,
				historyErrorVisible: false,
				historyErrorData: [],
				historyQuery: {
					pageNumber: 1,
					pageSize: 10
				},
				historyPageTotal: 0,
				roleType: '',
				sourceId: '',
				sourceVisible: false,
				sourceForm: {},
				isSmall: false,
				expands: []
			}
		},
		mounted() {
			this.getType()
			this.getSort()
			this.getTagList()
			this.getAll()
			this.getAllArea()
			if (this.page == 'famousQuestion') {
				this.query.appid = JSON.parse(localStorage.getItem('appid'))
				this.appChange(this.query.appid)
			}
			this.roleType = localStorage.getItem('roleType')
			this.getData()
		},
		methods: {
			appChange(id) {
				this.$forceUpdate()
				this.getSort(id)
				this.getData()
			},
			judgeImg(content) {
				let type = ['.jpg', '.png', '.jpeg', '.svg']
				for (let item of type) {
					if (content.indexOf(item) != -1) {
						return true
					}
				}
				return false
			},
			handleOk() {
				this.editVisible = false
				this.getData()
			},
			//添加试题来源
			async saveQuestionSource() {
				if (this.$.isEmpty(this.sourceForm.name)) {
					this.$message.warning('请输入来源名称!')
					return
				}
				if (this.$.isEmpty(this.sourceForm.area)) {
					this.$message.warning('请选择来源地区!')
					return
				}
				this.sourceForm.questionId = this.sourceId
				const res = await this.$post('/admin/question/saveQuestionSource', this.sourceForm)
				if (res.code == 1000) {
					this.$message.success('添加成功')
					this.sourceVisible = false
					this.getData()
				}
			},
			//来源地区变动
			areaChange(val) {
				this.sourceForm.province = ''
				this.sourceForm.city = ''
				if (val && val.length != 0) {
					this.sourceForm.province = val[0]
					this.sourceForm.city = val[1]
				}
			},
			//增加试题来源
			clickAddSource(row) {
				this.sourceId = row.id
				this.sourceVisible = true
				this.sourceForm = {}
				this.expands = [];
				this.expands.push(row.id);
			},
			//删除试题来源
			async questionSourceClose(id) {
				const res = await this.$postForm('/admin/question/deleteQuestionSource', {
					id
				})
				if (res.code == 1000) {
					this.$message.success('删除成功')
					this.getData()
				}
			},
			//批量添加
			async handleBatchAdd() {
				let ids = Array.from(this.multipleSelection, ({
					id
				}) => id)
				if (this.type == 1) {
					this.$post('/admin/examPaper/examPaperSyncSyn', ids).then(res => {
						if (res.code == 1000) {
							this.$message.success('添加成功')
							this.multipleSelection = []
							this.$refs.multipleTable.clearSelection()
							this.$emit('handleExamOk')
						}
					})
				} else {
					let params = {
						examPaperId: this.examPaperId,
						examPaperTypeId: this.examPaperTypeId,
						score: this.examPaperScore || 0,
						examId: this.examPaperId
					}
					const res = await this.$post('/admin/examPaper/addQuestions?' + this.$.getParamsString(params), ids)
					if (res.code == 1000) {
						this.$message.success('添加成功')
						this.multipleSelection = []
						this.$refs.multipleTable.clearSelection()
						this.$emit('handleExamOk')
					}
				}
				this.$refs.multipleTable.clearSelection()
				this.getData()
			},
			//获取省市区树
			async getAllArea() {
				const res = await this.$get('/admin/area/getAllArea')
				if (res.code == 1000) {
					this.areaData = res.data
					this.areaData.unshift({
						adcode: '0',
						name: '默认',
						parentId: 0,
						id: '0'
					})
				}
			},
			//获取历史纠错数据
			async getQuestionsHistory() {
				const res = await this.$post('/admin/question/getQuestionsHistory', this.historyQuery)
				if (res.code == 1000) {
					this.historyErrorData = res.data.list
					this.historyPageTotal = res.data.totalRow
				}
			},
			//历史纠错
			handleHistoryError(row) {
				this.historyQuery.questionId = row.id
				this.historyErrorVisible = true
				this.getQuestionsHistory()
			},
			// 点击下载图片
			handleDownloadAppQrIMg() {
				// 这里是获取到的图片base64编码
				var name = this.$refs.appQrCodeUrl.name;
				var img = document.getElementById('code').getElementsByTagName('img')[0];
				const imgUrl = img.src;
				// 如果浏览器支持msSaveOrOpenBlob方法（也就是使用IE浏览器的时候），那么调用该方法去下载图片
				if (window.navigator.msSaveOrOpenBlob) {
					let bstr = atob(imgUrl.split(',')[1]);
					let n = bstr.length;
					let u8arr = new Uint8Array(n);
					while (n--) {
						u8arr[n] = bstr.charCodeAt(n);
					}
					let blob = new Blob([u8arr]);
					window.navigator.msSaveOrOpenBlob(blob, name + '.' + 'png');
				} else {
					// 这里就按照chrome等新版浏览器来处理
					let a = document.createElement('a');
					a.href = imgUrl;
					a.setAttribute('download', name + '.' + 'png');
					a.click();
				}
			},
			// 二维码
			handleAppQrcode(row) {
				var vm = this;
				this.appQrcodeVisible = true;
				setTimeout(function() {
					vm.$refs.appQrCodeUrl.innerHTML = '';
					vm.$refs.appQrCodeUrl.name = row.title + '-' + row.type.name;
					var qrcode = new QRCode('code', {
						//text: 'https://zjbdapi.zhongshi.cn/h5/login.html?{"type":"question","id":"' + row.id +
							//'","appid":"' + row.appid + '"}', // 需要转换为二维码的内容
						text: 'https://admin.shuatibang.com/h5/login.html?{"type":"question","id":"' + row.id +
						'","appid":"' + row.appid + '"}', // 需要转换为二维码的内容
						width: 150,
						height: 150,
						colorDark: '#000000',
						colorLight: '#ffffff',
						correctLevel: QRCode.CorrectLevel.H
					});
				}, 200);
			},
			//删除
			async handleDel(id) {
				const res = await this.$postForm('/admin/question/deleteByIds', {
					ids: id
				})
				if (res.code == 1000) {
					this.$message.success('删除成功');
					this.getData()
				}
			},
			//获取科目
			async getAll() {
				const res = await this.$get('/admin/minis/getAll')
				if (res.code == 1000) {
					this.miniApps = res.data;
				}
			},
			//编辑
			handleEdit(row, type) {
				if (type == 1) {
					this.title = '编辑'
					if (this.page == 'smallQuestionList') {
						this.isSmall = true
					}
					setTimeout(() => {
						this.$refs.examQuestions.show(row.id)
					})
				} else {
					this.title = '添加到题库系统'
					setTimeout(() => {
						this.$refs.examQuestions.show(row.id, 2)
					})
				}
				this.editVisible = true
			},
			//获取主题目数据
			async getThemeData() {
				const res = await this.$postForm('/admin/question/questionParentId', this.themeQuery)
				if (res.code == 1000) {
					this.themeData = [res.data]
				}
			},
			//查看主题目
			clickTheme(row) {
				this.themeQuery.id = row.parentId
				this.getThemeData()
				this.themeVisible = true
			},
			//一键更新
			clickRenew() {
				setTimeout(() => {
					this.$refs.renew.show(this.page)
				})
			},
			//批量导出
			batchExport() {
				this.$refs.batchExport.show()
			},
			//批量修改标签
			async handleTagSave() {
				if (this.multipleSelection.length == 0) {
					this.$message.warning('请选择试题!')
					return
				}
				if (this.editTagForm.labelIds && this.editTagForm.labelIds.length != 0) {
					let ids = Array.from(this.multipleSelection, ({
						id
					}) => id)
					let labelIds = this.editTagForm.labelIds.join(',')
					const res = await this.$post('/admin/question/batchUpdateLabel?labelIds=' + labelIds, ids)
					if (res.code == 1000) {
						this.$message.success('操作成功')
						this.getData()
						this.editTagVisible = false
						this.$refs.multipleTable.clearSelection()
					}
				} else {
					this.$message.warning('请选择题目标签!')
				}
			},
			// 批量修改分类
			async handleCategorySave() {
				if (this.multipleSelection.length == 0) {
					this.$message.warning('请选择试题!')
					return
				}
				let arr = Array.from(this.multipleSelection, ({
					id
				}) => id)
				const res = await this.$post('/admin/question/batchUpdateCategory?' + this.$.getParamsString(this
					.editCategoryForm), arr)
				if (res.code == 1000) {
					this.$message.success('操作成功')
					this.getData()
					this.editCategoryVisible = false
					this.$refs.multipleTable.clearSelection()
				}
			},
			//批量删除
			delAllSelection() {
				this.$confirm('确定要批量删除已选中试题吗？', '提示', {
						type: 'warning'
					})
					.then(async () => {
						if (this.multipleSelection.length == 0) return
						let ids = Array.from(this.multipleSelection, ({
							id
						}) => id)
						const res = await this.$postForm('/admin/question/deleteByIds', {
							ids: ids.join(',')
						})
						if (res.code == 1000) {
							this.$message.success('删除成功')
							this.getData()
							this.multipleSelection = []
						}
					})
					.catch(() => {});
			},
			//获取标签下拉
			async getTagList() {
				const res = await this.$post('/admin/label/labelList')
				if (res.code == 1000) {
					this.tagList = res.data.list
				}
			},
			handlePageChange(val) {
				this.query.pageNumber = val
				this.getData();
			},
			handleSizeChange(val) {
				this.query.pageSize = val
				this.getData();
			},
			//历史纠错分页
			handleHistoryPageChange(val) {
				this.historyQuery.pageNumber = val
				this.getQuestionsHistory()
			},
			handleHistorySizeChange(val) {
				this.historyQuery.pageSize = val
				this.getQuestionsHistory()
			},
			handleThemePageChange(val) {
				this.themeQuery.pageNumber = val
				this.getThemeData();
			},
			handleThemeSizeChange(val) {
				this.themeQuery.pageSize = val
				this.getThemeData();
			},
			//是否开启纠错按钮
			async showCorrectingChange(val, row) {
				const res = await this.$postForm('/admin/question/saveQuestionCorrect', {
					id: row.id,
					showCorrecting: val
				})
				if (res.code == 1000) {
					this.$message.success('修改成功')
					this.getData()
				}
			},
			//查看看评论
			searchComment(id) {
				this.$refs.questionComment.show(id)
			},
			getExam(index, row) {
				this.$refs.associatedExam.show(row)
			},
			getVideoAnalysis(row) {
				this.$refs.associatedVideo.show(row.id)
			},
			handleSelectionChange(val) {
				this.multipleSelection = val
			},
			async getData() {
				if (this.examPaperId) {
					this.query.examId = this.examPaperId
				}
				if (this.type == 1) { //题库管理里的历年真题添加试
					this.$post('/admin/examPaper/pageExamPaperTi').then(res => {
						if (res.code == 1000) {
							this.tableData = res.data.list
							this.pageTotal = res.data.totalRow
						}
					})
				} else {
					this.query.isChild = this.page == 'smallQuestionList' ? true : false
					if (this.roleType == 3) {
						this.query.roleType = 1
					} else if (this.page == 'train') {
						this.query.roleType = 2
					} else {
						this.query.roleType = 1
					}
					const res = await this.$post(
						`/admin/question/getQuestions?pageNumber=${this.query.pageNumber}&pageSize=${this.query.pageSize}`, {
							...this.query,
							labelIds: this.query.labelIds ? this.query.labelIds.toString() : ''
						})
					if (res.code == 1000) {
						this.tableData = res.data.list
						this.pageTotal = res.data.totalRow
					}
				}

			},
			handleSearch() {
				this.query.pageNumber = 1
				this.getData();
			},
			handleRefresh() {
				this.query = {
					pageNumber: 1,
					pageSize: 30,
					labelIds: []
				}
				this.getData();
			},
			//获取题型
			async getType() {
				const res = await this.$get('/admin/questionType/getQuestionSort', this.query)
				if (res.code == 1000) {
					this.typeList = res.data
				}
			},
			getSort(id = localStorage.getItem('appid')) {
				this.$get('/admin/question/getQuestionCategorys', {
					type: 0,
					appid: id
				}).then(res => {
					if (res.code == 1000) {
						this.categoryId1Data = res.data.list
					}
				})
				this.$get('/admin/question/getQuestionCategorys', {
					type: 1,
					appid: id
				}).then(res => {
					if (res.code == 1000) {
						this.categoryId2Data = res.data.list
					}
				})
				this.$get('/admin/question/getQuestionCategorys', {
					type: 2,
					appid: id
				}).then(res => {
					if (res.code == 1000) {
						this.categoryId3Data = res.data.list
					}
				})
			}
		}
	}
</script>

<style scoped>
	/deep/ .el-table__header {
		/* // 使表格兼容safari，不错位,表头宽度较小 */
		width: 100%;
		table-layout: fixed !important;
	}

	/deep/ .el-table__body {
		width: 100%;
		/* // 使表格兼容safari，不错位 */
		table-layout: fixed !important;
	}
</style>